﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Api.Filter;
using Customer.Bussiness_Service;
using Entity.Sale;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ServiceCore;

namespace Customer.Areas.Work.Controllers
{

    [ApiController, Area("Work"), Route("/work/[action]"), Customer_Admin]
    public class WorkController : ControllerBase
    {
        private readonly Iwork_service _service;
        private readonly IToole_DI _tool;
        public WorkController(Iwork_service service, IToole_DI tool)
        {
            _service = service;
            _tool = tool;
        } 
        /// <summary>
        ///  请求工单列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultListModel<get_work_order_details_pagelist_showlisForwork> get_workorder_listForWork(get_work_order_details_pagelist_params query)
        {
            var result = _service.get_workorder_listForWork(query);
            return result;
        }

        /// <summary>
        ///  接单
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel work_get_order(string work_order_id)
        {
            var result = _service.work_get_order(work_order_id);
            _tool.di_es.Add_Log($"==接单==>请求:{Newtonsoft.Json.JsonConvert.SerializeObject(new { work_order_id })}==>结果:{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "work");
            return result;
        }

        /// <summary>
        ///  更改生产状态
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel change_work_state(string work_order_id, work_state? workstate)
        {
            var result = _service.change_work_state(work_order_id, workstate);
            _tool.di_es.Add_Log($"==更改生产状态==>请求:{Newtonsoft.Json.JsonConvert.SerializeObject(new { work_order_id, workstate })}==>结果:{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "work");
            return result;
        }
    }

}